<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
            v-model="queryParams.projectName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目编号" prop="projectId">
        <el-input
            v-model="queryParams.code"
            placeholder="请输入项目编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-tabs v-model="activeFinish" @tab-click="handleFinishClick">
      <el-tab-pane label="未结题" name="first"></el-tab-pane>
      <el-tab-pane label="已结题" name="second"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="projectList" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目编号" align="center" width="200" prop="code" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目负责人" prop="projectLeader"/>
      <el-table-column label="样品统计">
        <template #default="scope">
          <span>已出库{{scope.row.hasOut}}个，未出库{{scope.row.unOut}}个</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="toSampleList(scope.row.projectId)" >样品详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

  </div>
</template>

<script setup name="Project">

import {listItem} from "@/api/sample/sample.js";

const { proxy } = getCurrentInstance();

const projectList = ref([]);
const open = ref(false);
const loading = ref(false);//默认应为true
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const activeFinish=ref('first');

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    projectName: null,
    code: null,
    finish: false
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询实验列表 */
function getList() {
  loading.value = true;
  listItem(queryParams.value).then(response => {
    projectList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value.code=null;
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 转到样品清单页 */
function toSampleList(id){
  if (activeFinish.value=='first'){
    router.push({path:'/sample/sdetail',query:{id:id,finish:0}});
  }else{
    router.push({path:'/sample/sdetail',query:{id:id,finish:1}});
  }
}
function handleFinishClick(tab){
  if (tab.props.name=='second'){
    queryParams.value.finish=true;
  }else{
    queryParams.value.finish=false;
  }
  getList();
}
getList();
</script>
